// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
   menu1:[
      {path: "../images/food.png",name:"美食",
    },{path: "../images/market.png",name:"超市便利",
    },{path: "../images/vegitable.png",name:"蔬菜水果",
    },{path: "../images/medicine.png",name:"买药",
    },{path: "../images/milktea.png",name:"奶茶果汁",
    },
 ],
   menu2:[
    {path: "../images/tea.png",name:"下午茶",
    },{path: "../images/burgur.png",name:"汉堡披萨",
    },{path: "../images/flower.png",name:"浪漫鲜花",
    },{path: "../images/fastfood.png",name:"快餐简食",
    },{path: "../images/motor.png",name:"美团专送",
    },
  ],
  menu3: [
      {path: "../images/tea.png",name:"下午茶",
    },{path: "../images/burgur.png",name:"汉堡披萨",
    },{path: "../images/flower.png",name:"浪漫鲜花",
    },{path: "../images/fastfood.png",name:"快餐简食",
    },{path: "../images/motor.png",name:"美团专送",
    },
  ],
  menu4: [
      {path: "../images/tea.png",name:"下午茶",
    },{path: "../images/burgur.png",name:"汉堡披萨",
    },{path: "../images/flower.png",name:"浪漫鲜花",
    },{path: "../images/fastfood.png",name:"快餐简食",
    },{path: "../images/motor.png",name:"美团专送",
    },
  ],
  demos: ["demo1","demo2","demo3"],
  restaurant: [],
  location: [],
  },
  // 事件处理函数
  requestData(shop) {
    var that = this;
    var name = shop;
    var url = "https://www.fastmock.site/mock/990301ed5a510e8fb7f10a0b304fb79b/app/menu1/";
    wx.request({      
    url: url,
    //fast-mock生成的虚拟数据接口链接      
    method: "POST",
    data: {
        name: shop,
    },     
    success: function (res) {
      //成功得到数据，对数据进行处理      
      app.globalData.result = res.data.data.Menu;
      wx.navigateTo({
        url: '../menu/menu?name=' + shop,
      })
    } 
    });
  },
  orderRes(event){
    var param = event.currentTarget.dataset.item.name;
    this.requestData(param);
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  onShow: function () { 
    var that = this;
    wx.request({      
    url: "https://www.fastmock.site/mock/990301ed5a510e8fb7f10a0b304fb79b/app/show",
    //easy-mock生成的虚拟数据接口链接      
    method: "GET",     
    success: function (res) {
      //成功得到数据，对数据进行处理      
      that.setData({//将数据发送到data中          
        restaurant: res.data.data.restaurant, 
        location: wx.getStorageSync('location') 
      }) 
      } 
    });
   },
})
